package com.woniuxy.myorders.controller;

import com.woniuxy.commons.annotation.RequirePerms;
import com.woniuxy.commons.entity.OrdersLog;
import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.myorders.service.OrdersLogService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lhc
 * @create 2021-11-16 16:50
 */
@RestController
@RequestMapping("/myorders")
public class OrdersLogController {
    @Resource
    private OrdersLogService ordersLogService;

    /**
     * 分页查询
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @GetMapping("/AllOrdersLog")
    public ResponseResult<PageBean<OrdersLog>> getAllOrdersLog(Integer pageIndex, Integer pageSize) {
        List<OrdersLog> allOrdersLog = ordersLogService.getAllOrdersLog(pageIndex, pageSize);
        int count = ordersLogService.selectOrdersLogCount();
        PageBean<OrdersLog> ordersLogPageBean = new PageBean<>();
        ordersLogPageBean.setBeanList(allOrdersLog);
        ordersLogPageBean.setPageSize(pageSize);
        ordersLogPageBean.setPageIndex(pageIndex);
        ordersLogPageBean.setTotalRecord(count);
        return new ResponseResult<PageBean<OrdersLog>>(200, null, "查询成功", ordersLogPageBean);
    }

    /**
     * 删除日志
     * @param logid
     * @return
     */
    @RequirePerms("user:del")
    @DeleteMapping("/dellog/{logid}")
    public ResponseResult delOrdersLog(@PathVariable("logid") int logid) {
        ordersLogService.delOrdersLog(logid);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setMessage("删除成功");
        responseResult.setCode(200);
        System.out.println("删除成功"+logid);
        return responseResult;
    }
}